/**  
 * @Title: SmsDao.java
 * @Package org.wk.common.dao
 * @Description: TODO【】
 * @author df.w 
 * @date 2018年5月3日 下午5:04:41
 * @version V1.0  
 */ 

package org.wk.common.dao;

import java.util.Date;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.wk.common.domain.Sms;
import org.wk.core.db.dao.GenericJpaRepository;

import org.springframework.data.repository.query.Param;

/**
 * @ClassName	: SmsDao
 * @Package		：org.wk.common.dao
 * @Author df.w 
 * @Create Time	：2018年5月3日 下午5:04:41
 * @Description	: 
 */

public interface SmsDao extends GenericJpaRepository<Sms, String> {

	
	/**
	 * @Title		: findByMobileNumberAndSmsCodeTypeGreaterThanExpireTimeLimit1
	 * @Param		: @param mobileNum
	 * @Param		: @param smsCode
	 * @Param		: @param now
	 * @Param		: @return
	 * @Return Type 	：Sms
	 * @Description	: 
	 */ 
	@Query(value = "SELECT * FROM s_sms WHERE mobile_number =:mobileNum AND sms_code_type =:smsCodeType AND expire_time >:now ORDER BY send_time DESC LIMIT 0,1", nativeQuery = true)
	Sms findByMobileNumberAndSmsCodeTypeGreaterThanExpireTimeLimit1(@Param("mobileNum") String mobileNum, @Param("smsCodeType") String smsCodeType, @Param("now") Date now);

	
	/**
	 * @Title		: findByMobileNumberAndSmsCodeAndSmsCodeTypeAndSendTimeGreaterThan
	 * @Param		: @param mobileNumber
	 * @Param		: @param smsCode
	 * @Param		: @param smsCodeType
	 * @Param		: @param date
	 * @Param		: @return
	 * @Return Type 	：Sms
	 * @Description	: 判断某一刻之后是否发送过同类验证码
	 */ 
	@Query(value = "SELECT * FROM s_sms WHERE mobile_number =:mobileNum AND sms_code =:smsCode AND sms_code_type =:smsCodeType AND send_time >:now ORDER BY send_time DESC LIMIT 0,1", nativeQuery = true)
	Sms findByMobileNumberAndSmsCodeAndSmsCodeTypeAndSendTimeGreaterThan(@Param("mobileNum") String mobileNum, @Param("smsCode") String smsCode, @Param("smsCodeType") String smsCodeType, @Param("now") Date now);

}
